#include <stdio.h>
#include <stdlib.h>
#include "doge_mempool.h"

char *p = NULL;
char *p2 = NULL;
char *p3 = NULL;
char *p4 = NULL;

int main()
{
    char buf[100] = {"hello world!!!"};
    char buf2[100] = {"fuck C!!!!!!"};
    printf("dogemempool size %d\n", doge_mp_get_size());

    p = doge_mp_malloc(1020);
    if (p != NULL)
    {
        printf("malloc success %p\r\n", p);
    }

    memcpy(p, buf, strlen(buf));
    printf("%s\r\n", p);

    p2 = doge_mp_malloc(10);
    if (p2 == NULL)
    {
        printf("p2 malloc failed %p\r\n", p2);
    }

    if (doge_mp_free(p) == 0)
    {
        printf("p free success %p\r\n", p);
    }
    p = NULL;                         

    if (doge_mp_free(p2) == 0)
    {
        printf("p2 free success\r\n");
    }
    p2 = NULL;

    printf("p2 %p\r\n", p2);

    p2 = doge_mp_malloc(100);
    if (p2 == NULL)
    {
        printf("p2 malloc failed %p\r\n", p2);
    }
    else 
    {
        printf("p2 malloc success\r\n");
        memcpy(p2, buf, strlen(buf));
        printf("p2 %p, %s\r\n", p2, p2);
    }

    p3 = doge_mp_malloc(100);
    if (p3 == NULL)
    {
        printf("p3 malloc failed %p\r\n", p3);
    }
    else 
    {
        printf("p4 malloc success\r\n");
        memcpy(p3, buf2, strlen(buf2));
        printf("p3 %p, %s\r\n", p3, p3);
    }

    printf("p2 %p, %s\r\n", p2, p2);

    p4 = doge_mp_realloc(p2, 8);
    if (p4 == NULL)
    {
        printf("p4 malloc failed\r\n");
    }
    else
    {
        printf("p4 %p, %s\r\n", p4, p4);
    }

    if (doge_mp_free(p2) == 0)
    {
        printf("p2 free success %p\r\n", p2);
    }
    p2 = NULL;

    return 0;
}
